package com.media.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.base.model.R;
import com.media.mapper.PublishRecodeMapper;
import com.media.model.Publish;
import com.media.model.PublishRecode;
import com.media.service.PublishRecodeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.sql.Timestamp;
import java.util.Date;
import java.util.List;

/**
 * @Author: 小何
 * @Description: TODO
 * @DateTime: 2023/10/19 10:15
 **/
@Service
public class PublishRecodeServiceImpl extends ServiceImpl<PublishRecodeMapper, PublishRecode> implements PublishRecodeService {

    @Autowired
    private PublishRecodeService publishRecodeService;

    @Override
    public boolean audit(String publishId,Integer status,String reason,Integer auditorId) {
        UpdateWrapper<PublishRecode>uw=new UpdateWrapper<>();
        //以当前时间获取Timestamp
        Timestamp timestamp=new Timestamp(new Date().getTime());
        uw.eq("publishId",publishId)
                .set("status",status)
                .set("update_time",timestamp)
                .set("reason",reason)
                .set("auditorId",auditorId);
        return publishRecodeService.update(uw);
    }

    @Override
    public R<List<PublishRecode>> listPublishRecord(Integer page, Integer pageSize, Publish publish) {
        LambdaQueryWrapper<PublishRecode>qw=new LambdaQueryWrapper<>();
        qw.eq(PublishRecode::getStatus,0);
        List<PublishRecode> list = this.list(qw);
        return R.success(list);
    }

    @Override
    public R<String> transcodeSuccess(String publishId) {
        UpdateWrapper<PublishRecode>uw=new UpdateWrapper<>();
        uw.eq("publishId",publishId).set("status",0);
        boolean update = publishRecodeService.update(uw);
        return R.success("修改成功");
    }


}
